package com.szq.netty.client;

import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler;
import io.netty.channel.socket.DatagramPacket;

import java.nio.charset.Charset;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * @ClassName: MyClientHandler
 * @Description:
 * @Author: szq
 * @Date: 2021-11-11 14:14:16
 */
public class MyClientHandler extends SimpleChannelInboundHandler<DatagramPacket> {
    /**
     * 接收服务端发送的消息
     * @param ctx
     * @param packet
     */
    @Override
    protected void channelRead0(ChannelHandlerContext ctx, DatagramPacket packet) {
        String msg = packet.content().toString(Charset.forName("GBK"));
        System.out.println(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()) + " UDP客户端接收到消息：" + msg);
    }
}
